const mongoose = require("mongoose");

const schema = new mongoose.Schema(
  {
    title: String,
    name: String,
    user: { type: mongoose.SchemaTypes.ObjectId, ref: "User" },
  },
  { timestamps: true, versionKey: false },
);

schema.virtual("Documents", {
  ref: "Document", //绑定模型
  localField: "_id", //本地关联的键
  foreignField: "classify", // 目标关联的键
  justOne: false, // 是否返回一条
});

schema.virtual("tag", {
  ref: "Tag",
  localField: "_id",
  foreignField: "classify",
  justOne: false,
});

module.exports = mongoose.model("Classify", schema);
